<%
layout("/layouts/platform.html"){
%>
<div class="panel-body" style="padding-top: 15px;">
		<div class="box">
			<div class="box-body">
				<div class="col-sm-12">
					<div class="row">
				        <table class="table table-bordered table-hover mg-t datatable" style=" white-space: nowrap;
    text-overflow: ellipsis;">
                <thead>
                <tr>
                    <th>用户电话</th>
                    <th>来源</th>
                    <th>培训项目</th>
                    <th>培训方式</th>
                    <th>接送方式</th>
                    <th>订单类型</th>
                    <th>协议产品</th>
                    <th>分配驾校</th>
                    <th>分配教练</th>
                    <th>有效期</th>
                    <th>状态</th>
                    <th>操作</th>
   		        </table>
	    			</div>
				</div>
			</div>
		</div>
	</div>
<!-- 修改-->
	<div id="editModal" class="modal fade bs-modal-sm"   tabindex="-3" role="dialog" aria-hidden="true">
	    <div id="editModalDialog" class="modal-dialog " >
	        <div class="modal-content">
	        
	        </div>
	    </div>
	</div>
<script language="JavaScript">
	var datatable;
	function initDatatable() {
	    datatable = $('.datatable').DataTable({
	        "dom": '<"toolbar">frtip',
	        "searching": false,
	        "processing": false,
	        "serverSide": true,
	        "select": true,
	        "ordering": false,
	        "scrollX": true,
	        "language": {
	            "url": "${base}/assets/plugins/datatables/cn.json"
	        },
	        "preDrawCallback": function () {
	            sublime.showLoadingbar($(".main-content"));
	        },
	        "drawCallback": function () {
	            sublime.closeLoadingbar($(".main-content"));
	        },
	        "ajax": {
	            "url": "${base}/platform/train/contract/data",
	            "type": "post",
	            "data": function (d) {
	            }
	        },
	        "columns": [
	            {"data": "customer_id", "bSortable": true},
	            {"data": "source", "bSortable": true},
	            {"data": "project_id", "bSortable": true},
	            {"data": "train_mode", "bSortable": true},
	            {"data": "shuttle_mode", "bSortable": true},
	            {"data": "order_type", "bSortable": true},
	            {"data": "product_id", "bSortable": true},
	            {"data": "school_id", "bSortable": true},
	            {"data": "trainer_id", "bSortable": true},
	            {"data": "expiry_date", "bSortable": true},
	            {"data": "state", "bSortable": true}
	        ],
	        "columnDefs": [
				{
					"render": function (data, type, row) {
				        return getCustomer(data);
				     },
				     "targets": 0
				},
				{
					"render": function (data, type, row) {
						if(data==0){
							return "平台学员";
						}else if(data==1){
							return "外部学员";
						}else if(data==2){
							return "教练学员";
						}
				     },
				     "targets": 1
			 	},
			 	{
					"render": function (data, type, row) {
				        return getProject(data);
				     },
				     "targets": 2
				},
				{
					"render": function (data, type, row) {
						if(data=="0"){
							return "计时";
						}else if(data=="1"){
							return "包干";
						}
				     },
				     "targets": 3
			 	},
			 	{
					"render": function (data, type, row) {
						if(data=="0"){
							return "无接送";
						}else if(data=="1"){
							return "班车接送";
						}else if(data=="2"){
							return "定点接送";
						}
				     },
				     "targets": 4
			 	},
				{
					"render": function (data, type, row) {
				        return getProduct(data);
				     },
				     "targets": 6
				},
				{
					"render": function (data, type, row) {
				        return getSchool(data);
				     },
				     "targets": 7
				},
				{
					"render": function (data, type, row) {
				        return getTrainer(data);
				     },
				     "targets": 8
				},
				{
					"render": function (data, type, row) {
						if(data==-1){
							return "作废";
						}else if(data==0){
							return "培训中";
						}else if(data==1){
							return "已完成";
						}else if(data==2){
							return"已终止";
						}
				     },
				     "targets": 10
			 	},
			 	{
                    "render": function (data, type, row) {
                    	 return '<div>'
						 + '<a class="btn btn-xs btn btn-default " href="${base}/platform/train/contract/edit/' + row.id + '" data-toggle="modal" data-target="#editModal"><i class="fa fa-edit"></i>&nbsp;修改</a> '
						 + '</div>';
                    },
                    "targets": 11
                }
	        ]
	    });
	}
	$(function () {
	    initDatatable();
	    $("#editModal").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
	});
	//获取客户
	function getCustomer(id){
    	var datas="";
    	$.ajax({
			url : "${base}/platform/train/contract/getCustomer",
			data : {
				id : id
			},
			type : "post",
			async : false,
			dataType : "json",
			success : function(data){
				datas= data;
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				return false;
			}
		});
    	return datas;
    }
	//获取项目
	function getProject(id){
    	var datas="";
    	$.ajax({
			url : "${base}/platform/train/contract/getProject",
			data : {
				id : id
			},
			type : "post",
			async : false,
			dataType : "json",
			success : function(data){
				datas= data;
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				return false;
			}
		});
    	return datas;
    }
	//获取产品类型
	function getProduct(id){
    	var datas="";
    	$.ajax({
			url : "${base}/platform/train/contract/getProduct",
			data : {
				id : id
			},
			type : "post",
			async : false,
			dataType : "json",
			success : function(data){
				datas= data;
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				return false;
			}
		});
    	return datas;
    }
	//获取产品类型
	function getProduct(id){
    	var datas="";
    	$.ajax({
			url : "${base}/platform/train/contract/getProduct",
			data : {
				id : id
			},
			type : "post",
			async : false,
			dataType : "json",
			success : function(data){
				datas= data;
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				return false;
			}
		});
    	return datas;
    }
	//获取驾校
	function getSchool(id){
    	var datas="";
    	$.ajax({
			url : "${base}/platform/train/contract/getSchool",
			data : {
				id : id
			},
			type : "post",
			async : false,
			dataType : "json",
			success : function(data){
				datas= data;
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				return false;
			}
		});
    	return datas;
    }
	//获取教练
	function getTrainer(id){
    	var datas="";
    	$.ajax({
			url : "${base}/platform/train/contract/getTrainer",
			data : {
				id : id
			},
			type : "post",
			async : false,
			dataType : "json",
			success : function(data){
				datas= data;
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				return false;
			}
		});
    	return datas;
    }
	
	
</script>
<%}%>
